package com.tms.ned.controlmonitor.decorators;

import java.awt.Color;

import javax.swing.JComponent;

import com.tms.ned.controlmonitor.adapters.ComponentAdapter;

/*
 * Licensed under the Apache License, Version 2.0;<br> 
 * 
 * You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless 
 * required by applicable law or agreed to in writing, software distributed under the License 
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and limitations under the License. 
 */

public class TooltipComponentDecorator implements ComponentDecorator {

	private String validToolTipText = null;

	public TooltipComponentDecorator() {
		this(null);
	}

	public TooltipComponentDecorator(String validToolTipText) {
		this.validToolTipText = validToolTipText;
	}

	public final void decorateComponent(ComponentAdapter componentAdapter) {
		JComponent c = (JComponent) componentAdapter.getComponent();
		if (componentAdapter.getCurrentValidationStatus().isValid()) {
			c.setToolTipText(validToolTipText);
			c.setBackground(Color.white);
		} else {
			c.setBackground(Color.yellow.brighter());
			c.setToolTipText(componentAdapter.getCurrentValidationStatus().getMessage());
		}

		if (componentAdapter.isDirty()) {
			c.setForeground(Color.green.darker());
		} else {
			c.setForeground(Color.black);
		}
	}

}
